<template>
  <div class="page">
    <h3>基本信息</h3>
    <detail-table :list="baseInfo" :info="form"></detail-table>
    <zm-export ref="export" :api="exportApi()" type="warning" :params="form" v-show="false"></zm-export>
    <!-- <detail-customer
      v-if="customerParams.visible"
      v-model="customerParams.visible"
      :obj="customerParams.obj"
      :is-external="false"
    ></detail-customer> -->

    <detail-container
      v-if="extendDetailParams.visible"
      v-model="extendDetailParams.visible"
      :id="extendDetailParams.id"
      :business-id="extendDetailParams.id"
      :is-show-btn="false"
      :type="extendDetailParams.type"
    >
  </detail-container>
</div>
</template>

<script>
import DetailTable from '@/components/zmDetailTable'
import { base } from './const'
import {getInfo, exportInvoice} from '@/api/src/invoice'
import DetailContainer from '@/components/DetailContainer'

export default {
  name: 'InvoiceDataInfo',
  components: {
    DetailTable,
    DetailContainer
  },
  props: {
    obj: {
      type: Object,
      default: {}
    }
  },
  data () {
    return {
      base,
      form: {
        customerName: '',
        customerId: '',
        customerType: '',
        tradeType: '',
        customerStar: '',
        customerSource: '',

        linkMan: '',
        mobile: '',
        fixedMobile: '',
        email: '',

        regionName: '',
        address: '',
        belongCompany: '',
        invoiceCompany: '',
        companyScale: '',
        additionalInformation: '',

        saleMan: '',
        department: '',
        oldSaleMan: '',
        oldDepartment: '',
        createTime: '',
        updateTime: ''
      },
      extendDetailParams: {
        visible: false,
        id: '',
        businessId: '',
        type: ''
      }
    }
  },
  computed: {
    baseInfo () {
      return this.base(this)
    }
  },
  created () {
    this.getInfo()
  },
  methods: {
    exportApi () {
      return exportInvoice
    },
    async getInfo () {
      const res = await getInfo({id: this.obj.id})
      this.form = Object.assign({}, this.form, res)
    },
    onExtendShow (id, type) {
      this.extendDetailParams = {
        visible: true,
        id: id,
        businessId: id,
        type: type
      }
    },
    onExport () {
      if (!this.form.accessory) {
        this.$message.warning('没有找到下载的资料,确认是否有上传')
        return
      }
      let iframe = document.createElement('iframe')
      iframe.style.display = 'none'
      iframe.src = this.form.accessory
      iframe.onload = function () {
        document.body.removeChild(iframe)
      }
      document.body.appendChild(iframe)
    }
  }
}
</script>

<style scoped lang="scss">
.el-form-item {
  width: 50%;
}
.el-form-item__label {
  background: #ccc !important;
}
</style>
